//=============================================================================
// buildshadowmap.fx by Frank Luna (C) 2008 All Rights Reserved.
//
// Effect used to build the shadow map.
//=============================================================================

RasterizerState SHADOWBACK
{
    CullMode = 1;
    FillMode = Solid;
    MultisampleEnable = TRUE;
    DepthBias = 0.0;
    SlopeScaledDepthBias = 0.0;
};
RasterizerState SHADOWFRONT
{
    CullMode = 2;
    FillMode = Solid;
    MultisampleEnable = TRUE;
    DepthBias = 0.0;
    SlopeScaledDepthBias = 0.0;
};
BlendState noblend
{
	BlendEnable[0] = FALSE;
	SrcBlend = SRC_COLOR;
	DestBlend = INV_SRC_ALPHA;
	BlendOp = ADD;
	SrcBlendAlpha = ZERO;
	DestBlendAlpha = ZERO;
	BlendOpAlpha = ADD;
	RenderTargetWriteMask[0] = 0x0F;
};
RasterizerState EnableCulling
{
       CullMode = FRONT;
       // terrein dieper in zbuffer tekenene
       DepthBias = 8;
       // rekening houden met de hoeken van het terrein
       SlopeScaledDepthBias = 0.1f;
};
RasterizerState DisableCulling
{
       CullMode = FRONT;
       // terrein dieper in zbuffer tekenene
       DepthBias = 0;
       // rekening houden met de hoeken van het terrein
       SlopeScaledDepthBias = 0.0f;
};
cbuffer cbPerFrame
{
	float4x4 gLightWVP;
	float Bias;
	float SlopeScale;
};

// Nonnumeric values cannot be added to a cbuffer.
Texture2D gDiffuseMap;
Texture2D gDiffuseMap2;

SamplerState gTriLinearSam
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};

struct VS_IN
{
	float3 posL     : POSITION;
	float3 Norm		: NORMAL;
	float2 texC     : TEXCOORD;
};

struct VS_OUT
{
	float4 posH : SV_POSITION;
	float2 texC : TEXCOORD;
};
 
VS_OUT VS(VS_IN vIn)
{
	VS_OUT vOut;

	vOut.posH = mul(float4(vIn.posL, 1.0f), gLightWVP);
	vOut.texC = vIn.texC;
	
	return vOut;
}

void PS(VS_OUT pIn)
{
	float4 diffuse = gDiffuseMap.Sample( gTriLinearSam, pIn.texC );

	// Don't write transparent pixels to the shadow map.
	clip(diffuse.a - 0.15f);
}

technique10 BuildShadowMapTech
{
    pass P0
    {
		//SetRasterizerState(EnableCulling);
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( NULL );

		SetBlendState(noblend, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xffffffff);

    }
	//pass P1
    //{
		////SetRasterizerState(DisableCulling);
        //SetVertexShader( NULL );
        //SetGeometryShader( NULL );
        //SetPixelShader( NULL );
    //}
}
